//
//  ZDMyVoucherTableViewCell.m
//  xindailianmeng
//
//  Created by 张东 on 2017/2/16.
//  Copyright © 2017年 xindailianmeng.cn. All rights reserved.
//

#import "ZDMyVoucherTableViewCell.h"
#import "ZDMyVoucherModel.h"
#import "UIImageView+WebCache.h"
#import "ZHRTBasicMethod.h"
@interface ZDMyVoucherTableViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *backgroudImgView;

@property (weak, nonatomic) IBOutlet UILabel *denominationLb;
@property (weak, nonatomic) IBOutlet UILabel *postPeriodLb;
@property (weak, nonatomic) IBOutlet UILabel *limitInvestLb;
@property (weak, nonatomic) IBOutlet UILabel *getTimeLb;

@property (weak, nonatomic) IBOutlet UILabel *expirationTimeLb;

@property (weak, nonatomic) IBOutlet UIImageView *coverImgView;


@property (weak, nonatomic) IBOutlet UILabel *voucherStr;

@end

@implementation ZDMyVoucherTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self = [[NSBundle mainBundle] loadNibNamed:@"ZDMyVoucherTableViewCell" owner:self options:nil].firstObject;
    }
    return self;
}

- (void)setVoucherModel:(ZDMyVoucherModel *)voucherModel {
    
//    [self.backgroudImgView sd_setImageWithURL:[NSURL URLWithString:self.defaultVoucherPng] placeholderImage:nil options:SDWebImageRefreshCached];
    
    _voucherModel = voucherModel;
    
    if (voucherModel.voucherType == 1) {
        NSString *denominationStr = [NSString stringWithFormat:@"%@元",[ZHRTBasicMethod effectiveFigure:voucherModel.denomination]];
        NSMutableAttributedString *denominationAttr = [[NSMutableAttributedString alloc] initWithString:denominationStr];
        [denominationAttr addAttributes:@{NSFontAttributeName:kBaseFont_(16)} range:[denominationStr rangeOfString:@"元"]];
        self.denominationLb.textColor = kColorRGB(142,105,75);
        self.denominationLb.attributedText = denominationAttr;
        
       self.voucherStr.text = @"现金券";
    } else {
        NSString *denominationStr = [NSString stringWithFormat:@"%.2f%%",voucherModel.denomination];
        NSMutableAttributedString *denominationAttr = [[NSMutableAttributedString alloc] initWithString:denominationStr];

//        if (denominationStr.length > 2) {
//             NSRange range = [denominationStr rangeOfString:@"."];
//             NSLog(@"%@", NSStringFromRange(range));
//        } else {
         [denominationAttr addAttributes:@{NSFontAttributeName:kBaseFont_(40)} range: NSMakeRange(denominationStr.length - 3, 2)];
         [denominationAttr addAttributes:@{NSFontAttributeName:kBaseFont_(17)} range: NSMakeRange(denominationStr.length - 1, 1)];
            
//        }
       
        self.denominationLb.textColor = kColorRGB(142,105,75);
        self.denominationLb.attributedText = denominationAttr;
        
        self.voucherStr.text = @"加息券";
    }
 
    self.postPeriodLb.text = [NSString stringWithFormat:@"限%zd个月标含以上", voucherModel.postPeriod];
    
    self.limitInvestLb.text = [NSString stringWithFormat:@"单笔投资金额满%@元可使用",[ZHRTBasicMethod effectiveFigure:voucherModel.limitInvest]];
    
    self.getTimeLb.text = voucherModel.getTime;
    
    
    self.postPeriodLb.textColor = kColorRGB(142,105,75);
    
    self.limitInvestLb.textColor = kColorRGB(142,105,75);
    
    self.getTimeLb.textColor = kColorRGB(142,105,75);
    
    self.voucherStr.textColor = kColorRGB(142,105,75);
    
    
    self.expirationTimeLb.textColor = kColorRGB(142,105,75);
    NSString *expirationTimeStr = [NSString stringWithFormat:@"有效期至%@",voucherModel.expirationTime];
    NSMutableAttributedString *expirationTimeAttr = [[NSMutableAttributedString alloc] initWithString:expirationTimeStr];
    [expirationTimeAttr addAttributes:@{NSForegroundColorAttributeName:kColorRGB(168,168,168)} range:[expirationTimeStr rangeOfString:@"有效期至"]];
    self.expirationTimeLb.attributedText = expirationTimeAttr;
    
    if (voucherModel.status == 1) {
        self.coverImgView.alpha = 1;
    } else {
        self.coverImgView.alpha = 0;
    }
    
    self.contentView.backgroundColor = kColorRGB(234,234,234);
    
}


@end
